package top.yuhaitao;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;

public class Main {

	private static String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhJ7YEWhprKXkPd4fVXTHck6ZQx5Nzpfu" + "\r"
			+ "ThmBUODFV7gtoHlKJyKkn6NlGadmle5fEmsYZdqF5KBsm+XHy7kc9Dsdvy574J1J0dTLb0wVMW8H" + "\r" + "E+mJzhLYwBbRqMu/eq3X12WtoHYEdeU1emRA8MKjcCRRpbq63RW2S+TTO8FB/qaXDi9GDarruEae" + "\r"
			+ "cLyiPeFbNAAlWuVZ6N2iYhBzYvePERCsevszBPQH3C1vjM9ic3GpCNbM7dGie7J9Gd+l/CUnJA4E" + "\r" + "XiNE2AYTHg6NuFWJSl1r0uWuismB9z1mZIv9m0ETzlRf+9q7FccL57+DeA0e6NxxPM9SxoQ6E6x7" + "\r"
			+ "4qxFTQIDAQAB" + "\r";
	private static String PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCEntgRaGmspeQ93h9VdMdyTplD" + "\r"
			+ "Hk3Ol+5OGYFQ4MVXuC2geUonIqSfo2UZp2aV7l8Saxhl2oXkoGyb5cfLuRz0Ox2/LnvgnUnR1Mtv" + "\r" + "TBUxbwcT6YnOEtjAFtGoy796rdfXZa2gdgR15TV6ZEDwwqNwJFGlurrdFbZL5NM7wUH+ppcOL0YN" + "\r"
			+ "quu4Rp5wvKI94Vs0ACVa5Vno3aJiEHNi948REKx6+zME9AfcLW+Mz2JzcakI1szt0aJ7sn0Z36X8" + "\r" + "JSckDgReI0TYBhMeDo24VYlKXWvS5a6KyYH3PWZki/2bQRPOVF/72rsVxwvnv4N4DR7o3HE8z1LG" + "\r"
			+ "hDoTrHvirEVNAgMBAAECggEAXlYHaEqXcOIIOyH3s/f/r4XNa3rw6dYVA6UM4ZUhi0ZN3mqonrH7" + "\r" + "3DqEPf1f8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sJL04ZiCO3YMxl7ouyU" + "\r"
			+ "cLGNAoGAddxaE0WaO1VBnW7hXe4O0EJs5VIhr6eUJ4isvEcZPp4Leg/9MewpdaNF/HgfsY0ruZLz" + "\r" + "Iin1n/9hTzajSbHwteSV3az7jiYxZuK7pazrOxb6h3EezTbM0OSLL/AVltlzTyA7P27hQOY5dG/P" + "\r"
			+ "M1xxPC995b8spu5o3JfeqhhaWGw=" + "\r";

	public static void main(String[] args) throws UnsupportedEncodingException {

		String data = "{\"openid\":\"oDJ8_s2MdBLBNTRZmfZEpt7kMZPg\",\"name\":\"荀彧\",\"telephone\":\"13761495937\",\"idNo\":\"310110199301260539\"}";

		String encrypt = AsymmtricCryptoUtil.encrypt(data, PUBLIC_KEY);
		String base64Encode = Base64.encodeBase64String(encrypt.getBytes("UTF-8"));
		System.out.println("利用公钥加密之后的 " + base64Encode);
		String decrypt = AsymmtricCryptoUtil.decrypt(new String(Base64.decodeBase64(base64Encode)), PRIVATE_KEY);

		System.out.println("利用私钥解密之后的 " + decrypt);
		System.out.println(decrypt.equals(data));
	}

}
